package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Search implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("search book");
        Scanner scanner = new Scanner(System.in);
        System.out.print("input the name of the book you want to search");
        String name = scanner.nextLine();
        int index = -1;
        for (int i = 0; i < bookList.getBookNum(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                index = i;
                break;
            }
        }
        if(index != -1) {
            System.out.println(bookList.getBook(index));
        }else {
            System.out.println("this book is not exist");
        }
    }
}
